#include <stdio.h>
#define N 50
typedef struct CharacteristicsOfArraysOfIndexesAndLevels
{
    int max_level;
    int min_level;
    int max_index;
}Characteristics;

typedef struct Tree
{
    struct Tree* p_next_l;
    struct Tree* p_next_r;
    char* symbol;
    int index_end;
    int index_start;
    int level;
}NodeOfTree;

void createArithmeticExpression();

NodeOfTree* createRootOfTree();
int createTreeOfExpression(NodeOfTree* root, int current_index, char* m);
int createNodeOfSign (NodeOfTree* root, int current_index, char* m);
int createNodeOfNumber (NodeOfTree* root, int current_index, char* m);

int calculateAndWriteIndexesOfSymbols(NodeOfTree* p_head, int start);
int calculateAndWriteIndexesOfNumber(NodeOfTree* p_head, int start);
int calculateAndWriteIndexesOfSumOrDiffSignAndNextSymbols(NodeOfTree* p_head, int start);
int calculateAndWriteIndexesOfMultipSignAndNextSymbols(NodeOfTree* p_head, int start);
int calculateAndWriteIndexesOfDivSignAndNextSymbols(NodeOfTree* p_head, int start);
int calculateEndIndexOfSymbol(NodeOfTree* p_head, int start);
int calculateSumIndexesOfNextElements(NodeOfTree* p_head, int s);
int calculateSumIndexesAfterSumDifMultSign(NodeOfTree* p_head, int sum_of_indexes);
int calculateSumIndexesAfterDivisionSign(NodeOfTree* p_head, int sum_of_indexes);

void calculateAndWriteLevelOfSymbol(NodeOfTree* root, int level);
int returnLevelInNumerator(NodeOfTree* p_head);
int returnLevelInDenominator(NodeOfTree* p_head);
int sumLevelsOfNextElements(NodeOfTree* p_head, int current_sum_of_levels);

int fillArraysOfIndexesAndLevels(NodeOfTree* root, int* array_of_level, int* array_of_index, int current_index);
Characteristics calculateSizeOfArrayOfExpression(int* array_of_level, int* array_of_index);
int calculateQuantityOfBracketsInEnd(NodeOfTree* root, int quantity);

char** createTwoDimensionalArray(int width, int height);

void writeExpressionInArray(NodeOfTree* root, char** array, int max_level, int min_level, int max_index);
void writeMultiplicationSignInArray(char** array, NodeOfTree* p_head, int min_level);
NodeOfTree* returnPointerOfLeftNode(NodeOfTree* root);
NodeOfTree* returnPointerOfRightNode(NodeOfTree* root);

void printArray(char** array, int max_level, int min_level, int max_index);

void destroyTable(NodeOfTree* root);

